
#include <stdlib.h>
#include <iostream>
#include <string>
#include "sigslot.h"

using namespace std; 

struct Item 
{
	sigslot::signal2<int,int> Signal;
 
    void Check()
    {
        Signal(1,2);
		Signal.emit(3,4);
    }
};

struct Window : public sigslot::has_slots<> 
{
    void get(int i, int j)  
	{
	    cout<<i<<" window "<<j<<endl;  
	}
};

struct Window1 : public Window
{
    void get1(int i, int j)  
	{
	    cout<<i<<" window1 "<<j<<endl;  
	}
};

//--------------------------//
struct IEvent {};
typedef void (IEvent::*Fun)(int);
struct Event
{
public:
    Event() : m_fun(0){}
    void connect(IEvent* i,Fun fun)
    {
        m_fun = fun;
        m_this = i;
    }
    void emit(int data)
    {
        (m_this->*m_fun)(data);
    }
private:
    Fun m_fun;
    IEvent* m_this;
};
//--------------
struct Button
{
    Event e;
    void check()
    {
        e.emit(10);
    }
};

struct Test : public IEvent
{
    Button button;
    Test()
    {
        button.e.connect(this, reinterpret_cast<Fun>(&Test::test1));
    }
    void test1(int data)
    {
        cout << data << endl;
    }
    void check()
    {
        button.check();
    }
};
//--------------------------//

int main()
{
    Item item; 
    Window window;
    
	item.Signal.connect(&window, &Window::get); 
	item.Check();
	item.Signal.disconnect(&window);
    cout<<"---------"<<endl;
    Window1 window1;
    item.Signal.connect(&window1, &Window1::get1);

	item.Check();

    cout<<"---------"<<endl;
    Test test;
    test.check();

    _sleep(3456);
    return 0;
}


